package com.flx.dis.sharding.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.flx.dis.sharding.dao.StudentDao;
import com.flx.dis.sharding.dao.UserDao;
import com.flx.dis.sharding.entity.Student;
import com.flx.dis.sharding.entity.User;
import com.flx.dis.sharding.service.StudentService;
import com.flx.dis.sharding.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: Fenglixiong
 * @Date: 2021/6/9 17:57
 * @Description:
 */
@Slf4j
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    @Transactional
    public Long add(Student user) {
        studentDao.insert(user);
        log.info("add success id = "+user.getId());
        return user.getId();
    }

    @Override
    public Student get(Long id,Integer db) {
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        queryWrapper.eq("db",db);
        return studentDao.selectOne(queryWrapper);
    }
}
